class HealthmanageController < ApplicationController
  before_action :set_search, only: [:index, :query, :show , :search]
  def index
    @data = RecordResult.yaml_data
  end

  def score
    @record_result = RecordResult.new(name:params[:name],
                                    tel: params[:tel],
                                    card: params[:card],
                                    score1: params[:score1],
                                    score2: params[:score2],
                                    score3: params[:score3],
                                    score4: params[:score4],
                                    score5: params[:score5],
                                    score6: params[:score6],
                                    score7: params[:score7],
                                    score8: params[:score8],
                                    score9: params[:score9],
                                    sex: params[:sex],
                                    age: params[:age],
                                    add: params[:add])
    @record_result.save
  end

  def show
    @data = RecordResult.yaml_data
    @record_result = RecordResult.find(params[:id])
    render :index
  end

  # 结果查询
  def query
    @result = @q.result(distinct: true).order("ID desc").page(params[:page]).per(8)
  end

  #图表数据
  def echart
    @result = RecordResult.where(id: params[:id]).take
    @arry = Array.new
    @arry[0] = @result.real_score1
    @arry[1] = @result.real_score2
    @arry[2] = @result.real_score3
    @arry[3] = @result.real_score4
    @arry[4] = @result.real_score5
    @arry[5] = @result.real_score6
    @arry[6] = @result.real_score7
    @arry[7] = @result.real_score8
    @arry[8] = @result.real_score9

    @data = RecordResult.yaml_data
    @record_result = RecordResult.find(params[:id])
  end

  private

  def set_search
    @q = RecordResult.ransack(params[:q])
  end
end
